package cn.eoeit.mmy.interceptor;


import java.util.Arrays;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.log4j.Logger;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;

import com.google.common.base.Function;
import com.google.common.collect.Maps;




public class LogInterceptor extends HandlerInterceptorAdapter {
	
	private static final Logger LOG = Logger.getLogger(LogInterceptor.class);

	@Override
	public boolean preHandle(HttpServletRequest request,
			HttpServletResponse response, Object handler) throws Exception {
		
		Map<String,String[]> params = request.getParameterMap();
		Map<String,List<String>> convertParmas = Maps.transformValues(params, 
				new Function<String[], List<String>>() {
					public List<String> apply(String[] input) {
						return Arrays.asList(input);
					}
			
		});
		LOG.info("remoteAddr:{}"+
				request.getRemoteAddr()+",requestUri:{}"+
				request.getRequestURI()+",method:{},"+
				request.getMethod()+",queryString:{},"+
				request.getQueryString()+",params:{}"+
				convertParmas);
		return true;
	}

}
